// components/Header/index.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    title: {
      type: String,
      value: "标题"
    }
  },
  /**
   * 组件的初始数据
   */
  data: {
    navBarHeight:20,
    navHeight:40,
    isShowBack: false,    // 是否显示返回按钮
  },
  ready(){
    this.getBarHeight()
    this.initialBackStatus();
  },
  
  /**
   * 组件的方法列表
   */
  methods: {
    // 初始化返回按钮状态
    initialBackStatus(){
      const pages = getCurrentPages();
      this.setData({
        isShowBack: pages.length>=2
      })
    },
    // 返回事件
    backEvent(){
      wx.navigateBack();
    },
    //获取顶部高度
    getBarHeight(){
      let menuButtonObject = wx.getMenuButtonBoundingClientRect();
      wx.getSystemInfo({
        success: res => {
          console.log(res,menuButtonObject)
          let statusBarHeight = res.statusBarHeight,
            navTop = menuButtonObject.top,//胶囊按钮与顶部的距离
            navHeight =  menuButtonObject.height + (menuButtonObject.top - statusBarHeight)*2;//导航高度
            this.setData({
              navBarHeight: statusBarHeight,
              navHeight:navHeight,
            });
        },
        fail(err) {
          console.log(err);
        }
      })
    },
  },
})